#!/usr/bin/perl
#
# Copyright (c) 2012 Xumerle Luciano. All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#

##
## used to convert bed files from http://www.flemingtonlab.com/rnaseq.html
##

use strict;
use warnings;

open( FILE, $ARGV[0] ) || die "No bed file in input!!!\n\n";
while (<FILE>)
{
    chomp;
    next if ( m/^track/ || m/^\s*$/ );
    my @a = split /\t/;    # chrom,start,end,name,?,strand,???????
    my @gtf = ( $a[0], 'array', 'gene', $a[1], $a[2], '.', $a[5], '.' );
    push @gtf, qq|transcript_id "$a[3]"; gene_id "$a[3]"; gene_name "$a[3]"; |;
    $gtf[6] = '+' if ( $gtf[6] !~ m/[\-\+]/ );
    print join( "\t", @gtf ), "\n";
}
close FILE;
